﻿using System;
using System.Web.UI.WebControls;
using visinia.SmartEngine;

public partial class Admin_Editors_Editor : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //editor
        WebPageController.AddScriptLink(Page, WebRoots.GetJsRoot + "Editors/jHtmlArea/jHtmlArea-0.7.0.min.js");
        WebPageController.AddCssLink(Page, WebRoots.GetJsRoot + "Editors/jHtmlArea/style/jHtmlArea.css");  
      
        // added because the image plugin is displayed in a dialog box
        WebPageController.AddScriptLink(Page, WebRoots.GetJsRoot + "jquery/ui.core.js");
        WebPageController.AddScriptLink(Page, WebRoots.GetJsRoot + "jquery/ui.draggable.js");
        WebPageController.AddScriptLink(Page, WebRoots.GetJsRoot + "jquery/ui.resizable.js");
        WebPageController.AddScriptLink(Page, WebRoots.GetJsRoot + "jquery/ui.dialog.js");
        // visinia dialog styles override
        WebPageController.AddAdminThemeAwareCssLink(Page, "dialog.css");        
        // image plugin required
        WebPageController.AddScriptLink(Page, WebRoots.GetJsRoot + "jquery/ui.tabs.js");
        WebPageController.AddScriptLink(Page, WebRoots.GetAdminScriptsRoot + "media-library/media-library.js");
        WebPageController.AddCssLink(Page, WebRoots.GetAdminScriptsRoot +  "media-library/media-library.css");
       
        WebPageController.AddCssLink(Page, WebRoots.GetJsRoot + "Editors/jHtmlArea/visinia-editor.css");
        //visinia implemetation
        WebPageController.AddScriptLink(Page, WebRoots.GetAdminScriptsRoot + "Editor/visinia-editor.js");
    }    

    public string Text
    {
        get 
        {
            // ie gives this problem it automatically replaces the relative urls 
            // with the absolute urls
            string content = Editor.Text;
            string root = WebRoots.GetWebRoot;                      
            string replace = "src=\"" + root +"image.axd?picture=";
            string replaceWith = "src=\"image.axd?picture=";
            string fixedContent = content.Replace(replace, replaceWith);
            return fixedContent;
        }
        set { Editor.Text = value; }
    }
    
    public Unit Width
    {
        get { return Editor.Width; }
        set { Editor.Width = value; }
    }

    public Unit Height
    {
        get { return Editor.Height; }
        set { Editor.Height = value; }
    }
    
    public string CssClass
    {
        get { return Editor.CssClass; }
        set { Editor.CssClass += " " + value; }
    }
}